extends Line2D

@export var max_point_count : int = 12
var global_pos_history: Vector2
var is_drawing := false

func _ready():
	global_pos_history = global_position

func _process(_delta):
	# 添加当前帧位置（相对坐标需转换）
	add_point(Vector2(0, 0))
	for i in range(get_point_count() - 1):
		var pt_pos = get_point_position(i)
		set_point_position(i, pt_pos + global_pos_history - global_position)
	
	# 限制拖尾长度（如超过20点则移除最早的点）
	if get_point_count() > max_point_count :
		remove_point(0)
	
	global_rotation = 0  # 防止旋转导致扭曲:cite[1]
	global_pos_history = global_position

func start_trail():
	clear_points()
	set_process(true)

func stop_trail():
	set_process(false)
